package com.lyl.common.exception;

import cn.hutool.core.text.CharSequenceUtil;
import com.lyl.common.result.AbstractCode;
import com.lyl.common.result.BaseCode;
import lombok.Data;
import lombok.EqualsAndHashCode;

/**
 * @author Mr.Luo
 * @desc 自定义异常类
 */
@EqualsAndHashCode(callSuper = true)
@Data
public class BizException extends RuntimeException {
    private AbstractCode abstractCode;
    private String msg;

    public BizException(String msg) {
        this(BaseCode.BIZ_ERROR, msg);
    }

    public BizException(AbstractCode abstractCode) {
        this(abstractCode, null);
    }

    public BizException(AbstractCode abstractCode, String msg) {
        super(CharSequenceUtil.blankToDefault(msg, abstractCode.getMsg()));
        this.abstractCode = abstractCode;
        this.msg = CharSequenceUtil.blankToDefault(msg, abstractCode.getMsg());
    }
}
